package com.ricchieri.datamodel;

import java.util.List;

import javax.faces.model.ListDataModel;

import org.primefaces.model.SelectableDataModel;

import com.ricchieri.model.UserEmail;

public class UserEmailDataModel extends ListDataModel<UserEmail> implements SelectableDataModel<UserEmail> {  

    public UserEmailDataModel() {
    }

    public UserEmailDataModel(List<UserEmail> data) {
        super(data);
    }
    
    @Override
    public UserEmail getRowData(String rowKey) {

        @SuppressWarnings("unchecked")
		List<UserEmail> users = (List<UserEmail>) getWrappedData();
        
        for(UserEmail user : users) {
            if(user.getEmailType().equals(rowKey))
                return user;
        }
        
        return null;
    }

    @Override
    public Object getRowKey(UserEmail user) {
        return user.getEmailType();
    }
}
                    